<?php
namespace Android\Controller;

class CommonController extends BaseController {

    /**
     * 修改密码接口
     */
    public function editPwd() {

        $id = I ('request.id');
        $newPwd = I ('request.password');
        $role = I ('request.role');
        if (empty($id) || empty($newPwd) || empty($role))
            $this->out($this->fail,'空参数');

        $modelName = ucfirst(strtolower($role));
        if (!in_array($modelName,array('Teacher','Student')))
            $this->out($this->fail,'角色参数不正确');

        $flag = M ($modelName)->where("id = {$id}")->setField('password',md5($newPwd));
        if ($flag === false)
            $this->out($this->fail,'修改失败');
        $this->out($this->success,'修改成功',null);
    }

}